<include file="/public/header" />

<style>
    .layui-card-body {
        padding-left: 0;
    }
    .layui-form-item .layui-input-inline {
        width: 220px;
    }
</style>
 
<div class="layui-fluid" >
    <form class="layui-form layui-form-fixed" >
    <gt name="$data.id" value="0"><input type="text" name="id" value="{$data.id}" hidden=""></gt>
    <div class="layui-form-item">
        <label class="layui-form-label"><font color="red">* </font>{:__('会员名称')}</label>
        <div class="layui-input-inline">
            <input id="uid" ts-selected="{$data.user_id}" value="{$data.nickname|default=''}" 
                    placeholder="{:__('请选择会员名称')}" type="text" class="layui-input"  lay-verify="required" />
            <input name="uid" type="text" hidden="" value="{$data.user_id}">
        </div>
        <label class="layui-form-label">{:__('排序号')}</label>
        <div class="layui-input-inline">
            <input name="sort" placeholder="{:__('默认自动生成')}" value="{$data.sort}" type="number" class="layui-input"   />
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">{:__('接口地址')}</label>
        <div class="layui-input-inline">
            <input id="apiid" placeholder="{:__('请接口地址')}" value="{$data.class|default=''}"
                type="text" class="layui-input"   lay-verify="required" />
            <input name="api_id" type="text" hidden="" value="{$data.api_id}">
        </div>
        <label class="layui-form-label">{:__('接口状态')}</label>
        <div class="layui-input-inline">
            <input name="status" type="radio" value="1" title="{:__('正常')}" checked/>
            <input name="status" type="radio" value="0" title="{:__('停用')}"/>
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label"> <i class="layui-icon layui-icon-about" lay-tips="可限制间隔N秒执行一次！"></i> {:__('间隔/秒')}</label>
        <div class="layui-input-inline">
            <input name="seconds" placeholder="{:__('默认为不限制')}" value="{$data.seconds}" type="number" class="layui-input"   />
        </div>
        <label class="layui-form-label">{:__('每日上限')}</label>
        <div class="layui-input-inline">
            <input name="day" placeholder="{:__('默认为不限制')}" value="{$data.day}" type="number" class="layui-input"   />
        </div>
    </div> 

    <div class="layui-form-item">
        <label class="layui-form-label">{:__('QPS设置')}</label>
        <div class="layui-input-inline">
            <input name="qps" placeholder="{:__('默认为不限制')}" value="{$data.qps}" type="number" class="layui-input"   />
        </div>
        <label class="layui-form-label">{:__('总调用次数')}</label>
        <div class="layui-input-inline">
            <input name="ceiling" placeholder="{:__('默认为不限制')}" value="{$data.ceiling}" type="number" class="layui-input"   />
        </div>
    </div> 

    <div class="layui-form-item">
        <label class="layui-form-label">{:__('规则备注')}</label>
        <div class="layui-input-block" style="width: 560px;" >
            <textarea name="contents" id="content" cols="30" rows="10" style="min-height: 135px;" 
            placeholder="{:__('请输入规则备注')}" class="layui-textarea" >{$data.contents}</textarea>
        </div>
    </div>

    <div class="layui-footer" style="text-align: center;">
        <button class="layui-btn layui-btn-primary" type="button"  sa-event="closeDialog" >取消</button>
        <button class="layui-btn layui-btn-normal" lay-filter="submitIframe" lay-submit>提交</button>
    </div>
    </form>
</div>
<include file="/public/footer" />

<script>
    layui.use(['tableSelect'], function () {

        var tableSelect = layui.tableSelect;  

        var table = tableSelect.render({
            elem: '#uid', 
            checkedKey: 'id',
            searchKey: 'nickname',  
            searchPlaceholder: '关键词搜索', 
            table: {    
                url:"{:url('/system.user/index')}",
                limit: 50,
                cols: [[
                    {type: 'radio', title: '选项'},
                    {field: 'id',sort: true, width: 80 , title: 'ID'},
                    {field: 'nickname', width: 100 , title: '姓名'},
                    {field: 'email', width: 160, title: '邮箱'},
                    {field: 'createtime', width: 160,title: '创建时间'},
                ]]
            },
            done: function (elem, data) {
                elem.val(data.data[0].nickname);
                layui.$('input[name=uid]').val(data.data[0].id);
            }
        })

        var api = tableSelect.render({
            elem: '#apiid', 
            checkedKey: 'id',
            searchKey: 'title',  
            searchPlaceholder: '关键词搜索', 
            table: {    
                url:"{:url('/system.api/index')}",
                limit: 50,
                cols: [[
                    {type: 'radio',title: '选项'},
                    {field: 'id', width: 80, title: 'ID'},
                    {field: 'title', title: '接口名称'},
                    {field: 'class', title: '接口类方法'},
                    {field: 'method', align: 'center',templet: function (d) {
                        var strs = ['<span class="layui-badge layui-badge-green">GET</span>', 
                                    '<span class="layui-badge layui-badge-blue">POST</span>',
                                    '<span class="layui-badge layui-badge-red">不限</span>',
                                    ];
                        return strs[d.method];
                     }, title: '{:__("请求方式")}'},
                ]]
            }
            ,parseData: function(res){
                return {
                    "code": res.code, 
                    "msg": res.msg, 
                    "count": res.count,
                    "data": res.data.item 
                };
            },
            done: function (elem, data) {
                console.log(data);
                elem.val(data.data[0].class);
                layui.$('input[name=api_id]').val(data.data[0].id);
            }
        })

    });
</script>
